program sally
  use param
  use global
  implicit none
  integer :: ninp,nlog,nxec,nstp,nout,nras
  character(len=len_fn) :: fn
  call getarg(1,fn)
  ninp=20
  nlog=21
  nxec=22
  nstp=23
  nout=24
  nras=25
  call readinp(ninp,fn)
  call set_param
  call read_recoil(nras,rfn)
  ! Set log file name
  select case(rmode)
  case(1)
     fn='log_ssally'
  case(2)
     fn='log_xsally'
  case(3)
     fn='log_psally'
  end select
  ! Main loop
  open(unit=nlog,file=fn,status='replace')
  select case(rmode)
  case(1)
     open(unit=nxec,file=xfn,status='old',access='direct',recl=8)
     open(unit=nstp,file=pfn,status='old',access='direct',recl=8)
     call save_xsec(nlog,nxec)
     call save_nstop(nlog,nstp)
     call decompose(nlog,nxec,nstp,nout)
     close(nstp)
     close(nxec)
     call prnres(nlog,nout)
  case(2)
     call record_xsec(nlog,nout)
  case(3)
     call record_nstop(nlog,nout)
  case default
  end select
  close(nlog)
  call memfree
end program sally
